/*------------------------------------------------------------------------------
 * 
 * VPanel.java - Visual Studio style ui panel with caption bar
 * 
 * October 2009, Forhad Ahmed
 * 
 *------------------------------------------------------------------------------
 */

package ui.components.vs;

import java.awt.Graphics;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JComponent;

import ui.components.core.CComponent;
import application.Application;

/*
 * VPanel class.  As with all other components, can be constructed with a null
 * application handle.  Rendering is done with a visual studio look.
 */
public class VPanel extends CComponent {
    /*
     * Simple constructor
     */
    public VPanel() {
        super(null);
        initVPanel(null, null);
    }
    
    
    /*
     * Constructor
     */
    public VPanel(Application app) {
        super(app);
        initVPanel(null, null);
    }
    
    
    /*
     * Full form constructor
     */
    public VPanel(Application app, String title, JComponent contents) {
        super(app);
        initVPanel(title, contents);
    }
    
    
    /*
     * Constructor
     */
    public VPanel(JComponent contents) {
        super(null);
        initVPanel(null, contents);
    }
    
    
    /*
     * Constructor
     */
    public VPanel(String title, JComponent contents) {
        super(null);
        initVPanel(title, contents);
    }
    
    
    /*
     * Constructor guts
     */
    public void initVPanel(String title, JComponent contents) {
        this.title = (title == null ? "" : title);
        this.contents = contents;
        
        /*
         * Initialize the header and add it to the panel.
         */
        header = new VPanelHeader(this);
        this.add(header);
        
        /*
         * Initialize and attach resize handler to this panel itself
         */
        cadapter = new VPanelComponentAdapter(this);
        this.addComponentListener(cadapter);
    }
    
    
    /*
     * Paint the Panel.  Should be minimal work here as the header and contents
     * should do the bulk of the painting.
     */
    public void paint(Graphics g) {
        /*
         * TODO:
         */
    }
    
    
    /*
     * Handler for a resize action.  Called from the component event listener.
     */
    public void resize() {
        /*
         * TODO:
         */
    }


}


/*
 * VPanel component adapter.  Mainly for listening to size changes
 */
class VPanelComponentAdapter extends ComponentAdapter {
    /*
     * Constructor
     */
    public VPanelComponentAdapter(VPanel p) {
        panel = p;
    }
    
    
    /*
     * Size change callback.
     */
    public void componentResized(ComponentEvent e) {
        if (panel != null) {
            panel.resize();
        }
    }
    
    protected VPanel panel;
}







